#!/bin/sh
len=10

dictfile="/Users/hbaolong/workshop/gitee/3place/00说文解字/*"

if [ $# -ne 1 ];then
        echo "Usage: $0 file.md"
	exit -1;
fi

name=`echo $1 | sed -e "s/.md//" | sed -e "s/.*_//g"`

echo $name

sed -e "s/[.,()\n  1234567890？?~﹔．〕〔”’！：、abcdefghijklmnopqrstuvwxyz{}#△“‘，。\"；《》（）  ]//g" $1  |sed -e "s/./&\n/g" |sed -e "/^　$/d" |sed -e "/^$/d"  |sort |uniq -c |sort -rg  |awk '{print $2 "\t" $1}' |awk '{print $1}' >$1.OK

echo "% "$name "字典" > $name.dict.md
echo "% hbaolong@vip.qq.com" >> $name.dict.md
echo "" >> $name.dict.md

for files in `cat $1.OK`
do
	echo "#### "$files >>$name.dict.md

	echo "" >>$name.dict.md

	grep "^"$files  $dictfile >> $name.dict.md

	echo "" >> $name.dict.md
done

rm -f $1.OK

echo "the dict restore in "$name.dict.md
